/**
 * 2015-12-19
 * StudentController.java
 * author:sherlochao
 */
package com.sherlochao.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;
import com.sherlochao.beans.StudentBean;
import com.sherlochao.model.Course;
import com.sherlochao.model.Student;
import com.sherlochao.model.StudyCourse;
import com.sherlochao.model.Teacher;
import com.sherlochao.model.User;
import com.sherlochao.service.StudentService;

/**
 * @author yinchao
 *
 */
@Controller
@RequestMapping("/student")
public class StudentController {
	private static final Logger LOGGER = Logger.getLogger(StudentController.class);
	private String id;
	private Student student;
	private List<Student> studentList;
	
	public StudentController(){
		System.out.println("ooooooooooooooooooooooooooooooooooooooo");
	}
	@Resource
	private StudentService studentService;

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public Student getStudent() {
		return student;
	}

	public void setStudent(Student student) {
		this.student = student;
	}

	public List<Student> getStudentList() {
		return studentList;
	}

	public void setStudentList(List<Student> studentList) {
		this.studentList = studentList;
	}
	
//	@ResponseBody
//	@RequestMapping(value="/getStudent", method = RequestMethod.POST)
//	public Map<String,Object> getStudent(String studentId){
//		Map<String,Object> map = new HashMap<String,Object>();
//		Student student = studentService.get(studentId);
//		map.put("student", student);
//		List<StudyCourse> studyCourses = studentService.listStudyCourseByStudentId(studentId);
//		map.put("total", studyCourses.size());//所选课程总数
//		map.put("studyCourse", studyCourses);//所选课程的信息 成绩
//		List<Course> courses = studentService.listCourseByStudentId(studentId);
//		map.put("courseName", courses);
//		List<Teacher> teachers = studentService.listTeacherNameByStudentId(studentId);
//		map.put("teacherName", teachers);
//		return map;
//	}
	
	@ResponseBody
	@RequestMapping(value="/getStudent", method = RequestMethod.POST)
	public String getStudent(String studentId){
		StudentBean studentBean = new StudentBean();
		Student student = studentService.get(studentId);
		studentBean.setStudentId(student.getStudentId());
		studentBean.setStudentName(student.getStudentName());
		studentBean.setStudentBirthdate(student.getStudentBirthdate());
		List<StudyCourse> studyCourses = studentService
				.listStudyCourseByStudentId(studentId);
		studentBean.setCount(studyCourses.size());// 所选课程总数
		studentBean.setScores(studyCourses);// 所选课程的信息 成绩
		List<Course> courses = studentService.listCourseByStudentId(studentId);
		studentBean.setCourses(courses);
		List<Teacher> teachers = studentService
				.listTeacherNameByStudentId(studentId);
		studentBean.setTeachers(teachers);
		String json = JSON.toJSONString(studentBean);
		return json;
	}
    

}
